package com.subaiqiao.yunshiyuan.entrance.ysy.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subaiqiao.yunshiyuan.basis.mapper.BasisMapper;
import com.subaiqiao.yunshiyuan.entrance.ysy.pojo.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.subaiqiao.yunshiyuan.entrance.ysy.vo.ProductVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 曹朝禹
 * @since 2022-05-13
 */
@Mapper
public interface ProductMapper extends BasisMapper<Product> {

    @Select("SELECT product.*, a.product_category_name productCategoryName,b.sys_config_content sysConfigContent, b.sys_config_name sysConfigName " +
            "FROM `product` " +
            "LEFT JOIN product_category a ON product.product_type=a.product_category_id " +
            "LEFT JOIN sys_config b ON product.product_place_address=b.sys_config_id ${ew.customSqlSegment}")
    List<ProductVO> FillProductPage(Page<ProductVO> page, @Param(Constants.WRAPPER)QueryWrapper<ProductVO> wrapper);

    @Select("SELECT product.*, a.product_category_name productCategoryName,b.sys_config_content sysConfigContent, b.sys_config_name sysConfigName  " +
            "FROM `product` " +
            "LEFT JOIN product_category a ON product.product_type=a.product_category_id " +
            "LEFT JOIN sys_config b ON product.product_place_address=b.sys_config_id ${ew.customSqlSegment}")
    ProductVO FillProductDetails(@Param(Constants.WRAPPER)QueryWrapper<ProductVO> wrapper);

    @Select("SELECT COUNT(*) FROM product")
    Integer FindProductCount();

    @Select("SELECT COUNT(*) FROM product WHERE product_status=0")
    Integer FindInSellingGoodsCount();

    @Select("SELECT COUNT(*) FROM product WHERE product_status=1")
    Integer FindShortageOfGoodsCount();

    @Select("SELECT COUNT(*) FROM product WHERE TO_DAYS(NOW()) - TO_DAYS(create_datetime)=1")
    Integer FindProductCountYesterdayRegister();

    List<ProductVO> select_product_test_1();
}
